﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Noea.Graph
{
    // Represents a Vertex in a Directed Graph

    public class Vertex
    {
        private string name;
        private bool visited;
        private IList<Edge> edgeList;

        public Vertex(string name)
        {
            if (name.Length == 0) throw new Exception("The name of the vertex must not be empty!");
            visited = false;
            this.name = name;
            edgeList = new List<Edge>();
        }

		public bool Visited
		{
			set
			{
				this.visited = value;
			}
			get
			{
				return visited;
			}
		}

        public override string ToString()//For debugging purposes
        {
            return "[Vertex Name:" + Name + " Visited:" + Visited + "]";
        }

        public string Name
        {
            get
            {
                return name;
            }
            /*set
            {
                name = value;
            }*/
        }

        public IList<Edge> Edges() //must return a List in order to be able to remove edges
        {
            return edgeList;
        }

        public void AddEdgeTo(Vertex to)
        {
            Edge e = new Edge(this, to);
            edgeList.Add(e);
        }

        public Edge EdgeTo(Vertex v)
        {
            foreach (Edge edge in edgeList)
                if (edge.To == v) return edge;
            return null;
        }

        public int OutDegree()
        {
            return edgeList.Count;
        }

        public void RemoveEdgeTo(Vertex v)
        {
            Edge edge = EdgeTo(v);
            if (edge != null) edgeList.Remove(edge);
        }
    }

}

